#include <iostream>
#include <vector>
#include <cstring>
using namespace std;

typedef struct Edge
{
    int a;
    int b;
    int w;
    Edge(int x, int y, int z)
        :a(x)
        , b(y)
        , w(z)
    {}
} Edge;

const int N = 510;

int n, m, k;
int dist[N];
int backup[N];
vector<Edge> edge;

void Bellman_Ford()
{
    memset(dist, 0x3f, sizeof dist);
    dist[1] = 0;

    for (int i = 0; i < k; ++i)
    {
        memcpy(backup, dist, sizeof dist);
        for (auto e : edge)
        {
            int a = e.a, b = e.b, w = e.w;
            dist[b] = min(backup[a] + w, dist[b]);
        }
    }

    if (dist[n] > 0x3f3f3f3f / 2) cout << "impossible";
    else cout << dist[n];
}

int main()
{
    cin >> n >> m >> k;

    while (m--)
    {
        int x, y, z; cin >> x >> y >> z;

        edge.emplace_back(x, y, z);
    }

    Bellman_Ford();

    return 0;
}